#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
from LoopTestSequence import LoopTestSequence
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU


# This test executes standard loop with branch instructions in the loop body.
# The branch instructions can take the execution to a wide variety of possible
# addresses, so this test exercises the various mechanisms for generating loop
# control instructions depending on the distance from the end of the loop to
# the beginning.
class MainSequence(LoopTestSequence):
    def __init__(self, gen_thread, name=None):
        super().__init__(gen_thread, name)

        self._mInstructionWeights = {
            "ADDI##CALM": 10,
            "ADDW##CALM": 10,
            "JAL##CALM": 2,
            "JALR##CALM": 2,
            "LUI##CALM": 10,
            "SLLI#RV64I#CALM": 10,
            "SRLI#RV64I#CALM": 10,
        }

        if self.getGlobalState("AppRegisterWidth") == 32:
            self._mInstructionWeights = {
                "ADDI##CALM": 10,
                "JAL##CALM": 2,
                "JALR##CALM": 2,
                "LUI##CALM": 10,
                "SLLI#RV32I#CALM": 10,
                "SRLI#RV32I#CALM": 10,
            }

    # Return a dictionary of names of instructions to generate in the loop
    # body with their corresponding weights.
    def getInstructionWeights(self):
        return self._mInstructionWeights


MainSequenceClass = MainSequence
GenThreadClass = GenThreadGPGPU
EnvClass = EnvGPGPU
